package com.tomjun.permission.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.tomjun.common.JsonModel;
import com.tomjun.permission.mapper.UserDao;
import com.tomjun.permission.model.UserInfo;
import com.tomjun.permission.service.UserService;

@Service
public class UserServiceImpl implements UserService{
	@Autowired
	private UserDao userDao;
	/**
	 * 分页获取所有的用户信息
	 * @param page
	 * @param pageSize
	 * @param map
	 * @return
	 */
	@Override
	public JsonModel<Object> getAllUser(int page, int pageSize, Map<String, Object> map) {
		JsonModel<Object> js=new  JsonModel<Object>();
		int count=userDao.getUserCount(map);
		PageHelper.startPage(page, pageSize);
		List<UserInfo> list=userDao.getAllUser(map);
		js.setCount(count);
		js.setMsg("success");
		js.setCode(0);
		js.setData(list);
		return js;
	}
	/**
	 * 新增用户
	 * @param user
	 */
	@Override
	public void addUser(UserInfo user) {
		// TODO Auto-generated method stub
		userDao.addUser(user);
		
	}
	/**
	 * 修改用户
	 * @param user
	 */
	@Override
	public void updateUserInfo(UserInfo user) {
		// TODO Auto-generated method stub
		userDao.updateUserInfo(user);
	}
	/**
	 * 删除用户
	 * @param user
	 */
	@Override
	public void deleteUser(int userId) {
		// TODO Auto-generated method stub
		userDao.deleteUser(userId);
	}
	/**
	 * 查询用户是否存在
	 */
	@Override
	public Integer existUser(String userName) {
		// TODO Auto-generated method stub
		return userDao.existUser(userName);
	}

}
